//
//  AskForHelpInfoCell.m
//  HHBroker
//
//  Created by He Wei on 9/29/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "AskForHelpInfoCell.h"
#import "UIViewAdditions.h"
#import "HHLineView.h"
@implementation AskForHelpInfoCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.textLabel.font = [UIFont systemFontOfSize:14];
        self.textLabel.textColor = UIColorFromRGB(0x5d5d5d);
        [self.contentView addSubview:self.titleLabel];
        HHLineView *line = [HHLineView lineViewWithY:44];
        [self.contentView addSubview:line];
        [self.contentView addSubview:self.detailLabel];
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(AskForHelpInfoModel *)model
{
    _model = model;
    self.titleLabel.text = model.title;
    CGFloat height = [[self class] heightWithString:model.detail];
    self.detailLabel.height = height;
    self.detailLabel.text = model.detail;

}

+(CGFloat)heightWithString:(NSString *)string
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(kCurrentWidth-30, CGFLOAT_MAX)
                                        options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                     attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}
                                        context:nil];
    return rect.size.height+20;

}

+(CGFloat)heightWithModel:(AskForHelpInfoModel *)model
{
    CGFloat height = [self heightWithString:model.detail];
    return 45 + height;

}

- (void)layoutSubviews
{
    [super layoutSubviews];
}

#pragma mark - Setter && Getter
- (UILabel *)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, kCurrentWidth-30, 45)];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = UIColorFromRGB(0xff6a6a);
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;

}

- (UILabel *)detailLabel
{
    if (_detailLabel == nil) {
        _detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 45, kCurrentWidth-30, 44)];
        _detailLabel.font = [UIFont systemFontOfSize:14];
        _detailLabel.textColor = UIColorFromRGB(0x777777);
        _detailLabel.numberOfLines = 0;
    }

    return _detailLabel;
}


@end
